home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / unix / flex_2_3 / part07 < prev    next >
Encoding:
Internet Message Format  |  1990-08-19  |  34.2 KB

  1. Path: abcfd20.larc.nasa.gov!amiga-request
  2. From: amiga-request@abcfd20.larc.nasa.gov (Amiga Sources/Binaries Moderator)
  3. Subject: v90i234: flex 2.3 - fast lexical analyzer generator, Part07/13
  4. Reply-To: loftus@wpllabs.uucp (William P Loftus)
  5. Newsgroups: comp.sources.amiga
  6. Message-ID: <comp.sources.amiga:v90i234@abcfd20.larc.nasa.gov>
  7. Date: 19 Aug 90 22:42:50 GMT
  8. Approved: tadguy@uunet.UU.NET (Tad Guy)
  9. X-Mail-Submissions-To: amiga@uunet.uu.net
  10. X-Post-Discussions-To: comp.sys.amiga
  11.  
  12. Submitted-by: loftus@wpllabs.uucp (William P Loftus)
  13. Posting-number: Volume 90, Issue 234
  14. Archive-name: unix/flex-2.3/part07
  15.  
  16. #!/bin/sh
  17. # This is a shell archive.  Remove anything before this line, then unpack
  18. # it by saving it into a file and typing "sh file".  To overwrite existing
  19. # files, type "sh file -c".  You can also feed this as standard input via
  20. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  21. # will see the following message at the end:
  22. #        "End of archive 7 (of 13)."
  23. # Contents:  gen.c
  24. # Wrapped by tadguy@abcfd20 on Sun Aug 19 18:41:46 1990
  25. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  26. if test -f 'gen.c' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'gen.c'\"
  28. else
  29. echo shar: Extracting \"'gen.c'\" \(31559 characters\)
  30. sed "s/^X//" >'gen.c' <<'END_OF_FILE'
  31. X/* gen - actual generation (writing) of flex scanners */
  32. X
  33. X/*-
  34. X * Copyright (c) 1990 The Regents of the University of California.
  35. X * All rights reserved.
  36. X *
  37. X * This code is derived from software contributed to Berkeley by
  38. X * Vern Paxson.
  39. X * 
  40. X * The United States Government has rights in this work pursuant
  41. X * to contract no. DE-AC03-76SF00098 between the United States
  42. X * Department of Energy and the University of California.
  43. X *
  44. X * Redistribution and use in source and binary forms are permitted provided
  45. X * that: (1) source distributions retain this entire copyright notice and
  46. X * comment, and (2) distributions including binaries display the following
  47. X * acknowledgement:  ``This product includes software developed by the
  48. X * University of California, Berkeley and its contributors'' in the
  49. X * documentation or other materials provided with the distribution and in
  50. X * all advertising materials mentioning features or use of this software.
  51. X * Neither the name of the University nor the names of its contributors may
  52. X * be used to endorse or promote products derived from this software without
  53. X * specific prior written permission.
  54. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  55. X * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  56. X * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  57. X */
  58. X
  59. X#ifndef lint
  60. Xstatic char rcsid[] =
  61. X    "@(#) $Header: /usr/fsys/odin/a/vern/flex/RCS/gen.c,v 2.9 90/06/27 23:48:22 vern Exp $ (LBL)";
  62. X#endif
  63. X
  64. X#include "flexdef.h"
  65. X
  66. X
  67. X/* declare functions that have forward references */
  68. X
  69. Xvoid gen_next_state PROTO((int));
  70. Xvoid genecs PROTO(());
  71. Xvoid indent_put2s PROTO((char [], char []));
  72. Xvoid indent_puts PROTO((char []));
  73. X
  74. X
  75. Xstatic int indent_level = 0; /* each level is 4 spaces */
  76. X
  77. X#define indent_up() (++indent_level)
  78. X#define indent_down() (--indent_level)
  79. X#define set_indent(indent_val) indent_level = indent_val
  80. X
  81. X/* *everything* is done in terms of arrays starting at 1, so provide
  82. X * a null entry for the zero element of all C arrays
  83. X */
  84. Xstatic char C_short_decl[] = "static const short int %s[%d] =\n    {   0,\n";
  85. Xstatic char C_long_decl[] = "static const long int %s[%d] =\n    {   0,\n";
  86. Xstatic char C_state_decl[] =
  87. X    "static const yy_state_type %s[%d] =\n    {   0,\n";
  88. X
  89. X
  90. X/* indent to the current level */
  91. X
  92. Xvoid do_indent()
  93. X
  94. X    {
  95. X    register int i = indent_level * 4;
  96. X
  97. X    while ( i >= 8 )
  98. X    {
  99. X    putchar( '\t' );
  100. X    i -= 8;
  101. X    }
  102. X    
  103. X    while ( i > 0 )
  104. X    {
  105. X    putchar( ' ' );
  106. X    --i;
  107. X    }
  108. X    }
  109. X
  110. X
  111. X/* generate the code to keep backtracking information */
  112. X
  113. Xvoid gen_backtracking()
  114. X
  115. X    {
  116. X    if ( reject || num_backtracking == 0 )
  117. X    return;
  118. X
  119. X    if ( fullspd )
  120. X    indent_puts( "if ( yy_current_state[-1].yy_nxt )" );
  121. X    else
  122. X    indent_puts( "if ( yy_accept[yy_current_state] )" );
  123. X
  124. X    indent_up();
  125. X    indent_puts( "{" );
  126. X    indent_puts( "yy_last_accepting_state = yy_current_state;" );
  127. X    indent_puts( "yy_last_accepting_cpos = yy_cp;" );
  128. X    indent_puts( "}" );
  129. X    indent_down();
  130. X    }
  131. X
  132. X
  133. X/* generate the code to perform the backtrack */
  134. X
  135. Xvoid gen_bt_action()
  136. X
  137. X    {
  138. X    if ( reject || num_backtracking == 0 )
  139. X    return;
  140. X
  141. X    set_indent( 3 );
  142. X
  143. X    indent_puts( "case 0: /* must backtrack */" );
  144. X    indent_puts( "/* undo the effects of YY_DO_BEFORE_ACTION */" );
  145. X    indent_puts( "*yy_cp = yy_hold_char;" );
  146. X
  147. X    if ( fullspd || fulltbl )
  148. X    indent_puts( "yy_cp = yy_last_accepting_cpos + 1;" );
  149. X    else
  150. X    /* backtracking info for compressed tables is taken \after/
  151. X     * yy_cp has been incremented for the next state
  152. X     */
  153. X    indent_puts( "yy_cp = yy_last_accepting_cpos;" );
  154. X
  155. X    indent_puts( "yy_current_state = yy_last_accepting_state;" );
  156. X    indent_puts( "goto yy_find_action;" );
  157. X    putchar( '\n' );
  158. X
  159. X    set_indent( 0 );
  160. X    }
  161. X
  162. X
  163. X/* genctbl - generates full speed compressed transition table
  164. X *
  165. X * synopsis
  166. X *     genctbl();
  167. X */
  168. X
  169. Xvoid genctbl()
  170. X
  171. X    {
  172. X    register int i;
  173. X    int end_of_buffer_action = num_rules + 1;
  174. X
  175. X    /* table of verify for transition and offset to next state */
  176. X    printf( "static const struct yy_trans_info yy_transition[%d] =\n",
  177. X        tblend + numecs + 1 );
  178. X    printf( "    {\n" );
  179. X    
  180. X    /* We want the transition to be represented as the offset to the
  181. X     * next state, not the actual state number, which is what it currently is.
  182. X     * The offset is base[nxt[i]] - base[chk[i]].  That's just the
  183. X     * difference between the starting points of the two involved states
  184. X     * (to - from).
  185. X     *
  186. X     * first, though, we need to find some way to put in our end-of-buffer
  187. X     * flags and states.  We do this by making a state with absolutely no
  188. X     * transitions.  We put it at the end of the table.
  189. X     */
  190. X    /* at this point, we're guaranteed that there's enough room in nxt[]
  191. X     * and chk[] to hold tblend + numecs entries.  We need just two slots.
  192. X     * One for the action and one for the end-of-buffer transition.  We
  193. X     * now *assume* that we're guaranteed the only character we'll try to
  194. X     * index this nxt/chk pair with is EOB, i.e., 0, so we don't have to
  195. X     * make sure there's room for jam entries for other characters.
  196. X     */
  197. X
  198. X    base[lastdfa + 1] = tblend + 2;
  199. X    nxt[tblend + 1] = end_of_buffer_action;
  200. X    chk[tblend + 1] = numecs + 1;
  201. X    chk[tblend + 2] = 1; /* anything but EOB */
  202. X    nxt[tblend + 2] = 0; /* so that "make test" won't show arb. differences */
  203. X
  204. X    /* make sure every state has a end-of-buffer transition and an action # */
  205. X    for ( i = 0; i <= lastdfa; ++i )
  206. X    {
  207. X    register int anum = dfaacc[i].dfaacc_state;
  208. X
  209. X    chk[base[i]] = EOB_POSITION;
  210. X    chk[base[i] - 1] = ACTION_POSITION;
  211. X    nxt[base[i] - 1] = anum;    /* action number */
  212. X    }
  213. X
  214. X    for ( i = 0; i <= tblend; ++i )
  215. X    {
  216. X    if ( chk[i] == EOB_POSITION )
  217. X        transition_struct_out( 0, base[lastdfa + 1] - i );
  218. X
  219. X    else if ( chk[i] == ACTION_POSITION )
  220. X        transition_struct_out( 0, nxt[i] );
  221. X
  222. X    else if ( chk[i] > numecs || chk[i] == 0 )
  223. X        transition_struct_out( 0, 0 );        /* unused slot */
  224. X
  225. X    else    /* verify, transition */
  226. X        transition_struct_out( chk[i], base[nxt[i]] - (i - chk[i]) );
  227. X    }
  228. X
  229. X
  230. X    /* here's the final, end-of-buffer state */
  231. X    transition_struct_out( chk[tblend + 1], nxt[tblend + 1] );
  232. X    transition_struct_out( chk[tblend + 2], nxt[tblend + 2] );
  233. X
  234. X    printf( "    };\n" );
  235. X    printf( "\n" );
  236. X
  237. X    /* table of pointers to start states */
  238. X    printf( "static const struct yy_trans_info *yy_start_state_list[%d] =\n",
  239. X        lastsc * 2 + 1 );
  240. X    printf( "    {\n" );
  241. X
  242. X    for ( i = 0; i <= lastsc * 2; ++i )
  243. X    printf( "    &yy_transition[%d],\n", base[i] );
  244. X
  245. X    dataend();
  246. X
  247. X    if ( useecs )
  248. X    genecs();
  249. X    }
  250. X
  251. X
  252. X/* generate equivalence-class tables */
  253. X
  254. Xvoid genecs()
  255. X
  256. X    {
  257. X    register int i, j;
  258. X    static char C_char_decl[] = "static const %s %s[%d] =\n    {   0,\n";
  259. X    int numrows;
  260. X    Char clower();
  261. X
  262. X    if ( numecs < csize )
  263. X    printf( C_char_decl, "YY_CHAR", "yy_ec", csize );
  264. X    else
  265. X    printf( C_char_decl, "short", "yy_ec", csize );
  266. X
  267. X    for ( i = 1; i < csize; ++i )
  268. X    {
  269. X    if ( caseins && (i >= 'A') && (i <= 'Z') )
  270. X        ecgroup[i] = ecgroup[clower( i )];
  271. X
  272. X    ecgroup[i] = abs( ecgroup[i] );
  273. X    mkdata( ecgroup[i] );
  274. X    }
  275. X
  276. X    dataend();
  277. X
  278. X    if ( trace )
  279. X    {
  280. X    char *readable_form();
  281. X
  282. X    fputs( "\n\nEquivalence Classes:\n\n", stderr );
  283. X
  284. X    numrows = csize / 8;
  285. X
  286. X    for ( j = 0; j < numrows; ++j )
  287. X        {
  288. X        for ( i = j; i < csize; i = i + numrows )
  289. X        {
  290. X        fprintf( stderr, "%4s = %-2d", readable_form( i ), ecgroup[i] );
  291. X
  292. X        putc( ' ', stderr );
  293. X        }
  294. X
  295. X        putc( '\n', stderr );
  296. X        }
  297. X    }
  298. X    }
  299. X
  300. X
  301. X/* generate the code to find the action number */
  302. X
  303. Xvoid gen_find_action()
  304. X
  305. X    {
  306. X    if ( fullspd )
  307. X    indent_puts( "yy_act = yy_current_state[-1].yy_nxt;" );
  308. X
  309. X    else if ( fulltbl )
  310. X    indent_puts( "yy_act = yy_accept[yy_current_state];" );
  311. X
  312. X    else if ( reject )
  313. X    {
  314. X    indent_puts( "yy_current_state = *--yy_state_ptr;" );
  315. X    indent_puts( "yy_lp = yy_accept[yy_current_state];" );
  316. X
  317. X    puts( "find_rule: /* we branch to this label when backtracking */" );
  318. X
  319. X    indent_puts( "for ( ; ; ) /* until we find what rule we matched */" );
  320. X
  321. X    indent_up();
  322. X
  323. X    indent_puts( "{" );
  324. X
  325. X    indent_puts( "if ( yy_lp && yy_lp < yy_accept[yy_current_state + 1] )" );
  326. X    indent_up();
  327. X    indent_puts( "{" );
  328. X    indent_puts( "yy_act = yy_acclist[yy_lp];" );
  329. X
  330. X    if ( variable_trailing_context_rules )
  331. X        {
  332. X        indent_puts( "if ( yy_act & YY_TRAILING_HEAD_MASK ||" );
  333. X        indent_puts( "     yy_looking_for_trail_begin )" );
  334. X        indent_up();
  335. X        indent_puts( "{" );
  336. X
  337. X        indent_puts( "if ( yy_act == yy_looking_for_trail_begin )" );
  338. X        indent_up();
  339. X        indent_puts( "{" );
  340. X        indent_puts( "yy_looking_for_trail_begin = 0;" );
  341. X        indent_puts( "yy_act &= ~YY_TRAILING_HEAD_MASK;" );
  342. X        indent_puts( "break;" );
  343. X        indent_puts( "}" );
  344. X        indent_down();
  345. X
  346. X        indent_puts( "}" );
  347. X        indent_down();
  348. X
  349. X        indent_puts( "else if ( yy_act & YY_TRAILING_MASK )" );
  350. X        indent_up();
  351. X        indent_puts( "{" );
  352. X        indent_puts(
  353. X        "yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;" );
  354. X        indent_puts(
  355. X        "yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;" );
  356. X
  357. X        if ( real_reject )
  358. X        {
  359. X        /* remember matched text in case we back up due to REJECT */
  360. X        indent_puts( "yy_full_match = yy_cp;" );
  361. X        indent_puts( "yy_full_state = yy_state_ptr;" );
  362. X        indent_puts( "yy_full_lp = yy_lp;" );
  363. X        }
  364. X
  365. X        indent_puts( "}" );
  366. X        indent_down();
  367. X
  368. X        indent_puts( "else" );
  369. X        indent_up();
  370. X        indent_puts( "{" );
  371. X        indent_puts( "yy_full_match = yy_cp;" );
  372. X        indent_puts( "yy_full_state = yy_state_ptr;" );
  373. X        indent_puts( "yy_full_lp = yy_lp;" );
  374. X        indent_puts( "break;" );
  375. X        indent_puts( "}" );
  376. X        indent_down();
  377. X
  378. X        indent_puts( "++yy_lp;" );
  379. X        indent_puts( "goto find_rule;" );
  380. X        }
  381. X
  382. X    else
  383. X        {
  384. X        /* remember matched text in case we back up due to trailing context
  385. X         * plus REJECT
  386. X         */
  387. X        indent_up();
  388. X        indent_puts( "{" );
  389. X        indent_puts( "yy_full_match = yy_cp;" );
  390. X        indent_puts( "break;" );
  391. X        indent_puts( "}" );
  392. X        indent_down();
  393. X        }
  394. X
  395. X    indent_puts( "}" );
  396. X    indent_down();
  397. X
  398. X    indent_puts( "--yy_cp;" );
  399. X
  400. X    /* we could consolidate the following two lines with those at
  401. X     * the beginning, but at the cost of complaints that we're
  402. X     * branching inside a loop
  403. X     */
  404. X    indent_puts( "yy_current_state = *--yy_state_ptr;" );
  405. X    indent_puts( "yy_lp = yy_accept[yy_current_state];" );
  406. X
  407. X    indent_puts( "}" );
  408. X
  409. X    indent_down();
  410. X    }
  411. X
  412. X    else
  413. X    /* compressed */
  414. X    indent_puts( "yy_act = yy_accept[yy_current_state];" );
  415. X    }
  416. X
  417. X
  418. X/* genftbl - generates full transition table
  419. X *
  420. X * synopsis
  421. X *     genftbl();
  422. X */
  423. X
  424. Xvoid genftbl()
  425. X
  426. X    {
  427. X    register int i;
  428. X    int end_of_buffer_action = num_rules + 1;
  429. X
  430. X    printf( C_short_decl, "yy_accept", lastdfa + 1 );
  431. X
  432. X
  433. X    dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
  434. X
  435. X    for ( i = 1; i <= lastdfa; ++i )
  436. X    {
  437. X    register int anum = dfaacc[i].dfaacc_state;
  438. X
  439. X    mkdata( anum );
  440. X
  441. X    if ( trace && anum )
  442. X        fprintf( stderr, "state # %d accepts: [%d]\n", i, anum );
  443. X    }
  444. X
  445. X    dataend();
  446. X
  447. X    if ( useecs )
  448. X    genecs();
  449. X
  450. X    /* don't have to dump the actual full table entries - they were created
  451. X     * on-the-fly
  452. X     */
  453. X    }
  454. X
  455. X
  456. X/* generate the code to find the next compressed-table state */
  457. X
  458. Xvoid gen_next_compressed_state( char_map )
  459. Xchar *char_map;
  460. X
  461. X    {
  462. X    indent_put2s( "register YY_CHAR yy_c = %s;", char_map );
  463. X
  464. X    /* save the backtracking info \before/ computing the next state
  465. X     * because we always compute one more state than needed - we
  466. X     * always proceed until we reach a jam state
  467. X     */
  468. X    gen_backtracking();
  469. X
  470. X    indent_puts(
  471. X    "while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )" );
  472. X    indent_up();
  473. X    indent_puts( "{" );
  474. X    indent_puts( "yy_current_state = yy_def[yy_current_state];" );
  475. X
  476. X    if ( usemecs )
  477. X    {
  478. X    /* we've arrange it so that templates are never chained
  479. X     * to one another.  This means we can afford make a
  480. X     * very simple test to see if we need to convert to
  481. X     * yy_c's meta-equivalence class without worrying
  482. X     * about erroneously looking up the meta-equivalence
  483. X     * class twice
  484. X     */
  485. X    do_indent();
  486. X    /* lastdfa + 2 is the beginning of the templates */
  487. X    printf( "if ( yy_current_state >= %d )\n", lastdfa + 2 );
  488. X
  489. X    indent_up();
  490. X    indent_puts( "yy_c = yy_meta[yy_c];" );
  491. X    indent_down();
  492. X    }
  493. X
  494. X    indent_puts( "}" );
  495. X    indent_down();
  496. X
  497. X    indent_puts(
  498. X    "yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];" );
  499. X    }
  500. X
  501. X
  502. X/* generate the code to find the next match */
  503. X
  504. Xvoid gen_next_match()
  505. X
  506. X    {
  507. X    /* NOTE - changes in here should be reflected in gen_next_state() and
  508. X     * gen_NUL_trans()
  509. X     */
  510. X    char *char_map = useecs ? "yy_ec[*yy_cp]" : "*yy_cp";
  511. X    char *char_map_2 = useecs ? "yy_ec[*++yy_cp]" : "*++yy_cp";
  512. X    
  513. X    if ( fulltbl )
  514. X    {
  515. X    indent_put2s(
  516. X        "while ( (yy_current_state = yy_nxt[yy_current_state][%s]) > 0 )",
  517. X        char_map );
  518. X
  519. X    indent_up();
  520. X
  521. X    if ( num_backtracking > 0 )
  522. X        {
  523. X        indent_puts( "{" );
  524. X        gen_backtracking();
  525. X        putchar( '\n' );
  526. X        }
  527. X
  528. X    indent_puts( "++yy_cp;" );
  529. X
  530. X    if ( num_backtracking > 0 )
  531. X        indent_puts( "}" );
  532. X
  533. X    indent_down();
  534. X
  535. X    putchar( '\n' );
  536. X    indent_puts( "yy_current_state = -yy_current_state;" );
  537. X    }
  538. X
  539. X    else if ( fullspd )
  540. X    {
  541. X    indent_puts( "{" );
  542. X    indent_puts( "register const struct yy_trans_info *yy_trans_info;\n" );
  543. X    indent_puts( "register YY_CHAR yy_c;\n" );
  544. X    indent_put2s( "for ( yy_c = %s;", char_map );
  545. X    indent_puts(
  546. X    "      (yy_trans_info = &yy_current_state[yy_c])->yy_verify == yy_c;" );
  547. X    indent_put2s( "      yy_c = %s )", char_map_2 );
  548. X
  549. X    indent_up();
  550. X
  551. X    if ( num_backtracking > 0 )
  552. X        indent_puts( "{" );
  553. X
  554. X    indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
  555. X
  556. X    if ( num_backtracking > 0 )
  557. X        {
  558. X        putchar( '\n' );
  559. X        gen_backtracking();
  560. X        indent_puts( "}" );
  561. X        }
  562. X
  563. X    indent_down();
  564. X    indent_puts( "}" );
  565. X    }
  566. X
  567. X    else
  568. X    { /* compressed */
  569. X    indent_puts( "do" );
  570. X
  571. X    indent_up();
  572. X    indent_puts( "{" );
  573. X
  574. X    gen_next_state( false );
  575. X
  576. X    indent_puts( "++yy_cp;" );
  577. X
  578. X    indent_puts( "}" );
  579. X    indent_down();
  580. X
  581. X    do_indent();
  582. X
  583. X    if ( interactive )
  584. X        printf( "while ( yy_base[yy_current_state] != %d );\n", jambase );
  585. X    else
  586. X        printf( "while ( yy_current_state != %d );\n", jamstate );
  587. X
  588. X    if ( ! reject && ! interactive )
  589. X        {
  590. X        /* do the guaranteed-needed backtrack to figure out the match */
  591. X        indent_puts( "yy_cp = yy_last_accepting_cpos;" );
  592. X        indent_puts( "yy_current_state = yy_last_accepting_state;" );
  593. X        }
  594. X    }
  595. X    }
  596. X
  597. X
  598. X/* generate the code to find the next state */
  599. X
  600. Xvoid gen_next_state( worry_about_NULs )
  601. Xint worry_about_NULs;
  602. X
  603. X    { /* NOTE - changes in here should be reflected in get_next_match() */
  604. X    char char_map[256];
  605. X
  606. X    if ( worry_about_NULs && ! nultrans )
  607. X    {
  608. X    if ( useecs )
  609. X        (void) sprintf( char_map, "(*yy_cp ? yy_ec[*yy_cp] : %d)", NUL_ec );
  610. X    else
  611. X        (void) sprintf( char_map, "(*yy_cp ? *yy_cp : %d)", NUL_ec );
  612. X    }
  613. X
  614. X    else
  615. X    (void) strcpy( char_map, useecs ? "yy_ec[*yy_cp]" : "*yy_cp" );
  616. X
  617. X    if ( worry_about_NULs && nultrans )
  618. X    {
  619. X    if ( ! fulltbl && ! fullspd )
  620. X        /* compressed tables backtrack *before* they match */
  621. X        gen_backtracking();
  622. X
  623. X    indent_puts( "if ( *yy_cp )" );
  624. X    indent_up();
  625. X    indent_puts( "{" );
  626. X    }
  627. X   
  628. X    if ( fulltbl )
  629. X    indent_put2s( "yy_current_state = yy_nxt[yy_current_state][%s];", 
  630. X        char_map );
  631. X    
  632. X    else if ( fullspd )
  633. X    indent_put2s( "yy_current_state += yy_current_state[%s].yy_nxt;",
  634. X            char_map );
  635. X
  636. X    else
  637. X    gen_next_compressed_state( char_map );
  638. X
  639. X    if ( worry_about_NULs && nultrans )
  640. X    {
  641. X    indent_puts( "}" );
  642. X    indent_down();
  643. X    indent_puts( "else" );
  644. X    indent_up();
  645. X    indent_puts( "yy_current_state = yy_NUL_trans[yy_current_state];" );
  646. X    indent_down();
  647. X    }
  648. X    
  649. X    if ( fullspd || fulltbl )
  650. X    gen_backtracking();
  651. X
  652. X    if ( reject )
  653. X    indent_puts( "*yy_state_ptr++ = yy_current_state;" );
  654. X    }
  655. X
  656. X
  657. X/* generate the code to make a NUL transition */
  658. X
  659. Xvoid gen_NUL_trans()
  660. X
  661. X    { /* NOTE - changes in here should be reflected in get_next_match() */
  662. X    int need_backtracking = (num_backtracking > 0 && ! reject);
  663. X
  664. X    if ( need_backtracking )
  665. X    /* we'll need yy_cp lying around for the gen_backtracking() */
  666. X    indent_puts( "register YY_CHAR *yy_cp = yy_c_buf_p;" );
  667. X
  668. X    putchar( '\n' );
  669. X
  670. X    if ( nultrans )
  671. X    {
  672. X    indent_puts( "yy_current_state = yy_NUL_trans[yy_current_state];" );
  673. X    indent_puts( "yy_is_jam = (yy_current_state == 0);" );
  674. X    }
  675. X
  676. X    else if ( fulltbl )
  677. X    {
  678. X    do_indent();
  679. X    printf( "yy_current_state = yy_nxt[yy_current_state][%d];\n",
  680. X        NUL_ec );
  681. X    indent_puts( "yy_is_jam = (yy_current_state <= 0);" );
  682. X    }
  683. X
  684. X    else if ( fullspd )
  685. X    {
  686. X    do_indent();
  687. X    printf( "register int yy_c = %d;\n", NUL_ec );
  688. X
  689. X    indent_puts(
  690. X        "register const struct yy_trans_info *yy_trans_info;\n" );
  691. X    indent_puts( "yy_trans_info = &yy_current_state[yy_c];" );
  692. X    indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
  693. X
  694. X    indent_puts( "yy_is_jam = (yy_trans_info->yy_verify != yy_c);" );
  695. X    }
  696. X
  697. X    else
  698. X    {
  699. X    char NUL_ec_str[20];
  700. X
  701. X    (void) sprintf( NUL_ec_str, "%d", NUL_ec );
  702. X    gen_next_compressed_state( NUL_ec_str );
  703. X
  704. X    if ( reject )
  705. X        indent_puts( "*yy_state_ptr++ = yy_current_state;" );
  706. X
  707. X    do_indent();
  708. X
  709. X    if ( interactive )
  710. X        printf( "yy_is_jam = (yy_base[yy_current_state] == %d);\n",
  711. X            jambase );
  712. X    else
  713. X        printf( "yy_is_jam = (yy_current_state == %d);\n", jamstate );
  714. X    }
  715. X
  716. X    /* if we've entered an accepting state, backtrack; note that
  717. X     * compressed tables have *already* done such backtracking, so
  718. X     * we needn't bother with it again
  719. X     */
  720. X    if ( need_backtracking && (fullspd || fulltbl) )
  721. X    {
  722. X    putchar( '\n' );
  723. X    indent_puts( "if ( ! yy_is_jam )" );
  724. X    indent_up();
  725. X    indent_puts( "{" );
  726. X    gen_backtracking();
  727. X    indent_puts( "}" );
  728. X    indent_down();
  729. X    }
  730. X    }
  731. X
  732. X
  733. X/* generate the code to find the start state */
  734. X
  735. Xvoid gen_start_state()
  736. X
  737. X    {
  738. X    if ( fullspd )
  739. X    indent_put2s( "yy_current_state = yy_start_state_list[yy_start%s];",
  740. X        bol_needed ? " + (yy_bp[-1] == '\\n' ? 1 : 0)" : "" );
  741. X
  742. X    else
  743. X    {
  744. X    indent_puts( "yy_current_state = yy_start;" );
  745. X
  746. X    if ( bol_needed )
  747. X        {
  748. X        indent_puts( "if ( yy_bp[-1] == '\\n' )" );
  749. X        indent_up();
  750. X        indent_puts( "++yy_current_state;" );
  751. X        indent_down();
  752. X        }
  753. X
  754. X    if ( reject )
  755. X        {
  756. X        /* set up for storing up states */
  757. X        indent_puts( "yy_state_ptr = yy_state_buf;" );
  758. X        indent_puts( "*yy_state_ptr++ = yy_current_state;" );
  759. X        }
  760. X    }
  761. X    }
  762. X
  763. X
  764. X/* gentabs - generate data statements for the transition tables
  765. X *
  766. X * synopsis
  767. X *    gentabs();
  768. X */
  769. X
  770. Xvoid gentabs()
  771. X
  772. X    {
  773. X    int i, j, k, *accset, nacc, *acc_array, total_states;
  774. X    int end_of_buffer_action = num_rules + 1;
  775. X
  776. X    /* *everything* is done in terms of arrays starting at 1, so provide
  777. X     * a null entry for the zero element of all C arrays
  778. X     */
  779. X    static char C_char_decl[] =
  780. X    "static const YY_CHAR %s[%d] =\n    {   0,\n";
  781. X
  782. X    acc_array = allocate_integer_array( current_max_dfas );
  783. X    nummt = 0;
  784. X
  785. X    /* the compressed table format jams by entering the "jam state",
  786. X     * losing information about the previous state in the process.
  787. X     * In order to recover the previous state, we effectively need
  788. X     * to keep backtracking information.
  789. X     */
  790. X    ++num_backtracking;
  791. X
  792. X    if ( reject )
  793. X    {
  794. X    /* write out accepting list and pointer list
  795. X     *
  796. X     * first we generate the "yy_acclist" array.  In the process, we compute
  797. X     * the indices that will go into the "yy_accept" array, and save the
  798. X     * indices in the dfaacc array
  799. X     */
  800. X    int EOB_accepting_list[2];
  801. X
  802. X    /* set up accepting structures for the End Of Buffer state */
  803. X    EOB_accepting_list[0] = 0;
  804. X    EOB_accepting_list[1] = end_of_buffer_action;
  805. X    accsiz[end_of_buffer_state] = 1;
  806. X    dfaacc[end_of_buffer_state].dfaacc_set = EOB_accepting_list;
  807. X
  808. X    printf( C_short_decl, "yy_acclist", max( numas, 1 ) + 1 );
  809. X
  810. X    j = 1;    /* index into "yy_acclist" array */
  811. X
  812. X    for ( i = 1; i <= lastdfa; ++i )
  813. X        {
  814. X        acc_array[i] = j;
  815. X
  816. X        if ( accsiz[i] != 0 )
  817. X        {
  818. X        accset = dfaacc[i].dfaacc_set;
  819. X        nacc = accsiz[i];
  820. X
  821. X        if ( trace )
  822. X            fprintf( stderr, "state # %d accepts: ", i );
  823. X
  824. X        for ( k = 1; k <= nacc; ++k )
  825. X            {
  826. X            int accnum = accset[k];
  827. X
  828. X            ++j;
  829. X
  830. X            if ( variable_trailing_context_rules &&
  831. X             ! (accnum & YY_TRAILING_HEAD_MASK) &&
  832. X             accnum > 0 &&
  833. X             rule_type[accnum] == RULE_VARIABLE )
  834. X            {
  835. X            /* special hack to flag accepting number as part
  836. X             * of trailing context rule
  837. X             */
  838. X            accnum |= YY_TRAILING_MASK;
  839. X            }
  840. X
  841. X            mkdata( accnum );
  842. X
  843. X            if ( trace )
  844. X            {
  845. X            fprintf( stderr, "[%d]", accset[k] );
  846. X
  847. X            if ( k < nacc )
  848. X                fputs( ", ", stderr );
  849. X            else
  850. X                putc( '\n', stderr );
  851. X            }
  852. X            }
  853. X        }
  854. X        }
  855. X
  856. X    /* add accepting number for the "jam" state */
  857. X    acc_array[i] = j;
  858. X
  859. X    dataend();
  860. X    }
  861. X
  862. X    else
  863. X    {
  864. X    dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
  865. X
  866. X    for ( i = 1; i <= lastdfa; ++i )
  867. X        acc_array[i] = dfaacc[i].dfaacc_state;
  868. X
  869. X    /* add accepting number for jam state */
  870. X    acc_array[i] = 0;
  871. X    }
  872. X
  873. X    /* spit out "yy_accept" array.  If we're doing "reject", it'll be pointers
  874. X     * into the "yy_acclist" array.  Otherwise it's actual accepting numbers.
  875. X     * In either case, we just dump the numbers.
  876. X     */
  877. X
  878. X    /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
  879. X     * beginning at 0 and for "jam" state
  880. X     */
  881. X    k = lastdfa + 2;
  882. X
  883. X    if ( reject )
  884. X    /* we put a "cap" on the table associating lists of accepting
  885. X     * numbers with state numbers.  This is needed because we tell
  886. X     * where the end of an accepting list is by looking at where
  887. X     * the list for the next state starts.
  888. X     */
  889. X    ++k;
  890. X
  891. X    printf( C_short_decl, "yy_accept", k );
  892. X
  893. X    for ( i = 1; i <= lastdfa; ++i )
  894. X    {
  895. X    mkdata( acc_array[i] );
  896. X
  897. X    if ( ! reject && trace && acc_array[i] )
  898. X        fprintf( stderr, "state # %d accepts: [%d]\n", i, acc_array[i] );
  899. X    }
  900. X
  901. X    /* add entry for "jam" state */
  902. X    mkdata( acc_array[i] );
  903. X
  904. X    if ( reject )
  905. X    /* add "cap" for the list */
  906. X    mkdata( acc_array[i] );
  907. X
  908. X    dataend();
  909. X
  910. X    if ( useecs )
  911. X    genecs();
  912. X
  913. X    if ( usemecs )
  914. X    {
  915. X    /* write out meta-equivalence classes (used to index templates with) */
  916. X
  917. X    if ( trace )
  918. X        fputs( "\n\nMeta-Equivalence Classes:\n", stderr );
  919. X
  920. X    printf( C_char_decl, "yy_meta", numecs + 1 );
  921. X
  922. X    for ( i = 1; i <= numecs; ++i )
  923. X        {
  924. X        if ( trace )
  925. X        fprintf( stderr, "%d = %d\n", i, abs( tecbck[i] ) );
  926. X
  927. X        mkdata( abs( tecbck[i] ) );
  928. X        }
  929. X
  930. X    dataend();
  931. X    }
  932. X
  933. X    total_states = lastdfa + numtemps;
  934. X
  935. X    printf( tblend > MAX_SHORT ? C_long_decl : C_short_decl,
  936. X        "yy_base", total_states + 1 );
  937. X
  938. X    for ( i = 1; i <= lastdfa; ++i )
  939. X    {
  940. X    register int d = def[i];
  941. X
  942. X    if ( base[i] == JAMSTATE )
  943. X        base[i] = jambase;
  944. X
  945. X    if ( d == JAMSTATE )
  946. X        def[i] = jamstate;
  947. X
  948. X    else if ( d < 0 )
  949. X        {
  950. X        /* template reference */
  951. X        ++tmpuses;
  952. X        def[i] = lastdfa - d + 1;
  953. X        }
  954. X
  955. X    mkdata( base[i] );
  956. X    }
  957. X
  958. X    /* generate jam state's base index */
  959. X    mkdata( base[i] );
  960. X
  961. X    for ( ++i /* skip jam state */; i <= total_states; ++i )
  962. X    {
  963. X    mkdata( base[i] );
  964. X    def[i] = jamstate;
  965. X    }
  966. X
  967. X    dataend();
  968. X
  969. X    printf( tblend > MAX_SHORT ? C_long_decl : C_short_decl,
  970. X        "yy_def", total_states + 1 );
  971. X
  972. X    for ( i = 1; i <= total_states; ++i )
  973. X    mkdata( def[i] );
  974. X
  975. X    dataend();
  976. X
  977. X    printf( lastdfa > MAX_SHORT ? C_long_decl : C_short_decl,
  978. X        "yy_nxt", tblend + 1 );
  979. X
  980. X    for ( i = 1; i <= tblend; ++i )
  981. X    {
  982. X    if ( nxt[i] == 0 || chk[i] == 0 )
  983. X        nxt[i] = jamstate;    /* new state is the JAM state */
  984. X
  985. X    mkdata( nxt[i] );
  986. X    }
  987. X
  988. X    dataend();
  989. X
  990. X    printf( lastdfa > MAX_SHORT ? C_long_decl : C_short_decl,
  991. X        "yy_chk", tblend + 1 );
  992. X
  993. X    for ( i = 1; i <= tblend; ++i )
  994. X    {
  995. X    if ( chk[i] == 0 )
  996. X        ++nummt;
  997. X
  998. X    mkdata( chk[i] );
  999. X    }
  1000. X
  1001. X    dataend();
  1002. X    }
  1003. X
  1004. X
  1005. X/* write out a formatted string (with a secondary string argument) at the
  1006. X * current indentation level, adding a final newline
  1007. X */
  1008. X
  1009. Xvoid indent_put2s( fmt, arg )
  1010. Xchar fmt[], arg[];
  1011. X
  1012. X    {
  1013. X    do_indent();
  1014. X    printf( fmt, arg );
  1015. X    putchar( '\n' );
  1016. X    }
  1017. X
  1018. X
  1019. X/* write out a string at the current indentation level, adding a final
  1020. X * newline
  1021. X */
  1022. X
  1023. Xvoid indent_puts( str )
  1024. Xchar str[];
  1025. X
  1026. X    {
  1027. X    do_indent();
  1028. X    puts( str );
  1029. X    }
  1030. X
  1031. X
  1032. X/* make_tables - generate transition tables
  1033. X *
  1034. X * synopsis
  1035. X *     make_tables();
  1036. X *
  1037. X * Generates transition tables and finishes generating output file
  1038. X */
  1039. X
  1040. Xvoid make_tables()
  1041. X
  1042. X    {
  1043. X    register int i;
  1044. X    int did_eof_rule = false;
  1045. X
  1046. X    skelout();
  1047. X
  1048. X    /* first, take care of YY_DO_BEFORE_ACTION depending on yymore being used */
  1049. X    set_indent( 2 );
  1050. X
  1051. X    if ( yymore_used )
  1052. X    {
  1053. X    indent_puts( "yytext -= yy_more_len; \\" );
  1054. X    indent_puts( "yyleng = yy_cp - yytext; \\" );
  1055. X    }
  1056. X
  1057. X    else
  1058. X    indent_puts( "yyleng = yy_cp - yy_bp; \\" );
  1059. X
  1060. X    set_indent( 0 );
  1061. X    
  1062. X    skelout();
  1063. X
  1064. X
  1065. X    printf( "#define YY_END_OF_BUFFER %d\n", num_rules + 1 );
  1066. X
  1067. X    if ( fullspd )
  1068. X    { /* need to define the transet type as a size large
  1069. X       * enough to hold the biggest offset
  1070. X       */
  1071. X    int total_table_size = tblend + numecs + 1;
  1072. X    char *trans_offset_type =
  1073. X        total_table_size > MAX_SHORT ? "long" : "short";
  1074. X
  1075. X    set_indent( 0 );
  1076. X    indent_puts( "struct yy_trans_info" );
  1077. X    indent_up();
  1078. X        indent_puts( "{" );
  1079. X        indent_puts( "short yy_verify;" );
  1080. X
  1081. X        /* in cases where its sister yy_verify *is* a "yes, there is a
  1082. X     * transition", yy_nxt is the offset (in records) to the next state.
  1083. X     * In most cases where there is no transition, the value of yy_nxt
  1084. X     * is irrelevant.  If yy_nxt is the -1th  record of a state, though,
  1085. X     * then yy_nxt is the action number for that state
  1086. X         */
  1087. X
  1088. X        indent_put2s( "%s yy_nxt;", trans_offset_type );
  1089. X        indent_puts( "};" );
  1090. X    indent_down();
  1091. X
  1092. X    indent_puts( "typedef const struct yy_trans_info *yy_state_type;" );
  1093. X    }
  1094. X    
  1095. X    else
  1096. X    indent_puts( "typedef int yy_state_type;" );
  1097. X
  1098. X    if ( fullspd )
  1099. X    genctbl();
  1100. X
  1101. X    else if ( fulltbl )
  1102. X    genftbl();
  1103. X
  1104. X    else
  1105. X    gentabs();
  1106. X
  1107. X    if ( num_backtracking > 0 )
  1108. X    {
  1109. X    indent_puts( "static yy_state_type yy_last_accepting_state;" );
  1110. X    indent_puts( "static YY_CHAR *yy_last_accepting_cpos;\n" );
  1111. X    }
  1112. X
  1113. X    if ( nultrans )
  1114. X    {
  1115. X    printf( C_state_decl, "yy_NUL_trans", lastdfa + 1 );
  1116. X
  1117. X    for ( i = 1; i <= lastdfa; ++i )
  1118. X        {
  1119. X        if ( fullspd )
  1120. X        {
  1121. X        if ( nultrans )
  1122. X            printf( "    &yy_transition[%d],\n", base[i] );
  1123. X        else
  1124. X            printf( "    0,\n" );
  1125. X        }
  1126. X        
  1127. X        else
  1128. X        mkdata( nultrans[i] );
  1129. X        }
  1130. X
  1131. X    dataend();
  1132. X    }
  1133. X
  1134. X    if ( ddebug )
  1135. X    { /* spit out table mapping rules to line numbers */
  1136. X    indent_puts( "extern int yy_flex_debug;" );
  1137. X    indent_puts( "int yy_flex_debug = 1;\n" );
  1138. X
  1139. X    printf( C_short_decl, "yy_rule_linenum", num_rules );
  1140. X    for ( i = 1; i < num_rules; ++i )
  1141. X        mkdata( rule_linenum[i] );
  1142. X    dataend();
  1143. X    }
  1144. X
  1145. X    if ( reject )
  1146. X    {
  1147. X    /* declare state buffer variables */
  1148. X    puts(
  1149. X    "static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr;" );
  1150. X    puts( "static YY_CHAR *yy_full_match;" );
  1151. X    puts( "static int yy_lp;" );
  1152. X
  1153. X    if ( variable_trailing_context_rules )
  1154. X        {
  1155. X        puts( "static int yy_looking_for_trail_begin = 0;" );
  1156. X        puts( "static int yy_full_lp;" );
  1157. X        puts( "static int *yy_full_state;" );
  1158. X        printf( "#define YY_TRAILING_MASK 0x%x\n", YY_TRAILING_MASK );
  1159. X        printf( "#define YY_TRAILING_HEAD_MASK 0x%x\n",
  1160. X            YY_TRAILING_HEAD_MASK );
  1161. X        }
  1162. X
  1163. X    puts( "#define REJECT \\" );
  1164. X        puts( "{ \\" );
  1165. X        puts(
  1166. X    "*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \\" );
  1167. X        puts(
  1168. X        "yy_cp = yy_full_match; /* restore poss. backed-over text */ \\" );
  1169. X
  1170. X    if ( variable_trailing_context_rules )
  1171. X        {
  1172. X        puts( "yy_lp = yy_full_lp; /* restore orig. accepting pos. */ \\" );
  1173. X        puts(
  1174. X        "yy_state_ptr = yy_full_state; /* restore orig. state */ \\" );
  1175. X        puts(
  1176. X        "yy_current_state = *yy_state_ptr; /* restore curr. state */ \\" );
  1177. X        }
  1178. X
  1179. X        puts( "++yy_lp; \\" );
  1180. X        puts( "goto find_rule; \\" );
  1181. X        puts( "}" );
  1182. X    }
  1183. X    
  1184. X    else
  1185. X    {
  1186. X    puts( "/* the intent behind this definition is that it'll catch" );
  1187. X    puts( " * any uses of REJECT which flex missed" );
  1188. X    puts( " */" );
  1189. X    puts( "#define REJECT reject_used_but_not_detected" );
  1190. X    }
  1191. X    
  1192. X    if ( yymore_used )
  1193. X    {
  1194. X    indent_puts( "static int yy_more_flag = 0;" );
  1195. X    indent_puts( "static int yy_doing_yy_more = 0;" );
  1196. X    indent_puts( "static int yy_more_len = 0;" );
  1197. X    indent_puts(
  1198. X        "#define yymore() { yy_more_flag = 1; }" );
  1199. X    indent_puts(
  1200. X        "#define YY_MORE_ADJ (yy_doing_yy_more ? yy_more_len : 0)" );
  1201. X    }
  1202. X
  1203. X    else
  1204. X    {
  1205. X    indent_puts( "#define yymore() yymore_used_but_not_detected" );
  1206. X    indent_puts( "#define YY_MORE_ADJ 0" );
  1207. X    }
  1208. X
  1209. X    skelout();
  1210. X
  1211. X    if ( ferror( temp_action_file ) )
  1212. X    flexfatal( "error occurred when writing temporary action file" );
  1213. X
  1214. X    else if ( fclose( temp_action_file ) )
  1215. X    flexfatal( "error occurred when closing temporary action file" );
  1216. X
  1217. X    temp_action_file = fopen( action_file_name, "r" );
  1218. X
  1219. X    if ( temp_action_file == NULL )
  1220. X    flexfatal( "could not re-open temporary action file" );
  1221. X
  1222. X    /* copy prolog from action_file to output file */
  1223. X    action_out();
  1224. X
  1225. X    skelout();
  1226. X
  1227. X    set_indent( 2 );
  1228. X
  1229. X    if ( yymore_used )
  1230. X    {
  1231. X    indent_puts( "yy_doing_yy_more = yy_more_flag;" );
  1232. X    indent_puts( "if ( yy_doing_yy_more )" );
  1233. X    indent_up();
  1234. X    indent_puts( "{" );
  1235. X    indent_puts( "yy_more_len = yyleng;" );
  1236. X    indent_puts( "yy_more_flag = 0;" );
  1237. X    indent_puts( "}" );
  1238. X    indent_down();
  1239. X    }
  1240. X
  1241. X    skelout();
  1242. X
  1243. X    gen_start_state();
  1244. X
  1245. X    /* note, don't use any indentation */
  1246. X    puts( "yy_match:" );
  1247. X    gen_next_match();
  1248. X
  1249. X    skelout();
  1250. X    set_indent( 2 );
  1251. X    gen_find_action();
  1252. X
  1253. X    skelout();
  1254. X    if ( ddebug )
  1255. X    {
  1256. X    indent_puts( "if ( yy_flex_debug )" );
  1257. X    indent_up();
  1258. X
  1259. X    indent_puts( "{" );
  1260. X    indent_puts( "if ( yy_act == 0 )" );
  1261. X    indent_up();
  1262. X    indent_puts( "fprintf( stderr, \"--scanner backtracking\\n\" );" );
  1263. X    indent_down();
  1264. X
  1265. X    do_indent();
  1266. X    printf( "else if ( yy_act < %d )\n", num_rules );
  1267. X    indent_up();
  1268. X    indent_puts(
  1269. X    "fprintf( stderr, \"--accepting rule at line %d (\\\"%s\\\")\\n\"," );
  1270. X    indent_puts( "         yy_rule_linenum[yy_act], yytext );" );
  1271. X    indent_down();
  1272. X
  1273. X    do_indent();
  1274. X    printf( "else if ( yy_act == %d )\n", num_rules );
  1275. X    indent_up();
  1276. X    indent_puts(
  1277. X    "fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\"," );
  1278. X    indent_puts( "         yytext );" );
  1279. X    indent_down();
  1280. X
  1281. X    do_indent();
  1282. X    printf( "else if ( yy_act == %d )\n", num_rules + 1 );
  1283. X    indent_up();
  1284. X    indent_puts( "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );" );
  1285. X    indent_down();
  1286. X
  1287. X    do_indent();
  1288. X    printf( "else\n" );
  1289. X    indent_up();
  1290. X    indent_puts( "fprintf( stderr, \"--EOF\\n\" );" );
  1291. X    indent_down();
  1292. X
  1293. X    indent_puts( "}" );
  1294. X    indent_down();
  1295. X    }
  1296. X
  1297. X    /* copy actions from action_file to output file */
  1298. X    skelout();
  1299. X    indent_up();
  1300. X    gen_bt_action();
  1301. X    action_out();
  1302. X
  1303. X    /* generate cases for any missing EOF rules */
  1304. X    for ( i = 1; i <= lastsc; ++i )
  1305. X    if ( ! sceof[i] )
  1306. X        {
  1307. X        do_indent();
  1308. X        printf( "case YY_STATE_EOF(%s):\n", scname[i] );
  1309. X        did_eof_rule = true;
  1310. X        }
  1311. X    
  1312. X    if ( did_eof_rule )
  1313. X    {
  1314. X    indent_up();
  1315. X    indent_puts( "yyterminate();" );
  1316. X    indent_down();
  1317. X    }
  1318. X
  1319. X
  1320. X    /* generate code for handling NUL's, if needed */
  1321. X
  1322. X    /* first, deal with backtracking and setting up yy_cp if the scanner
  1323. X     * finds that it should JAM on the NUL
  1324. X     */
  1325. X    skelout();
  1326. X    set_indent( 7 );
  1327. X
  1328. X    if ( fullspd || fulltbl )
  1329. X    indent_puts( "yy_cp = yy_c_buf_p;" );
  1330. X    
  1331. X    else
  1332. X    { /* compressed table */
  1333. X    if ( ! reject && ! interactive )
  1334. X        {
  1335. X        /* do the guaranteed-needed backtrack to figure out the match */
  1336. X        indent_puts( "yy_cp = yy_last_accepting_cpos;" );
  1337. X        indent_puts( "yy_current_state = yy_last_accepting_state;" );
  1338. X        }
  1339. X    }
  1340. X
  1341. X
  1342. X    /* generate code for yy_get_previous_state() */
  1343. X    set_indent( 1 );
  1344. X    skelout();
  1345. X
  1346. X    if ( bol_needed )
  1347. X    indent_puts( "register YY_CHAR *yy_bp = yytext;\n" );
  1348. X
  1349. X    gen_start_state();
  1350. X
  1351. X    set_indent( 2 );
  1352. X    skelout();
  1353. X    gen_next_state( true );
  1354. X
  1355. X    set_indent( 1 );
  1356. X    skelout();
  1357. X    gen_NUL_trans();
  1358. X
  1359. X    skelout();
  1360. X
  1361. X    /* copy remainder of input to output */
  1362. X
  1363. X    line_directive_out( stdout );
  1364. X    (void) flexscan(); /* copy remainder of input to output */
  1365. X    }
  1366. END_OF_FILE
  1367. if test 31559 -ne `wc -c <'gen.c'`; then
  1368.     echo shar: \"'gen.c'\" unpacked with wrong size!
  1369. fi
  1370. # end of 'gen.c'
  1371. fi
  1372. echo shar: End of archive 7 \(of 13\).
  1373. cp /dev/null ark7isdone
  1374. MISSING=""
  1375. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 ; do
  1376.     if test ! -f ark${I}isdone ; then
  1377.     MISSING="${MISSING} ${I}"
  1378.     fi
  1379. done
  1380. if test "${MISSING}" = "" ; then
  1381.     echo You have unpacked all 13 archives.
  1382.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1383. else
  1384.     echo You still need to unpack the following archives:
  1385.     echo "        " ${MISSING}
  1386. fi
  1387. ##  End of shell archive.
  1388. exit 0
  1389. -- 
  1390. Mail submissions (sources or binaries) to <amiga@uunet.uu.net>.
  1391. Mail comments to the moderator at <amiga-request@uunet.uu.net>.
  1392. Post requests for sources, and general discussion to comp.sys.amiga.
  1393.